// pages/nome/nome.js
const nomeCards = require("../../mock/data/nome");
const utils = require('../../utils/util.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    checkAll: false
  },
  toggleSelect(event){
    const _index = event.currentTarget.dataset.index;
    let list = [].concat(this.data.list);
    let checkAll = true;
    list.map((item, index)=>{
      if(index==_index){
        item.checked = !item.checked
      }
      if(!item.checked){
          checkAll = false
      }
    })
    this.setData({list, checkAll})
  },
  toggleSelectAll(){
    let list = [].concat(this.data.list);
    list.map((item, index) => {
        item.checked = !this.data.checkAll
    })
    this.setData({ 
      list, 
      checkAll: !this.data.checkAll 
    })
  },
  sendCard(){
    let list = [];
    this.data.list.map((item) => {
      if(!item.checked){
        list.push(item)
      }
    })
    console.log(list)
    if(list.length===this.data.list.length){
      wx.showToast({
        icon: 'none',
        title: '请先选择接收人',
      })
      return false
    }
    this.setData({
      list
    })
    wx.showToast({
      icon: 'none',
      title: '发送成功',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('options', options)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    let list = nomeCards.map((item) => {
      item.checked = false;
      return item
    })
    this.setData({
      list
    })
  },
  onShow: function () {
  
  },
  ...utils.defaultShare

})